package com.xinqi.modules.discuss.discuss.factory;

import com.xinqi.common.base.error.CommonErrors;
import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.discuss.discuss.client.CourseDiscussStudentLogClient;
import com.xinqi.modules.discuss.discuss.dto.req.CourseDiscussStudentLogCreateDTO;
import com.xinqi.modules.discuss.discuss.dto.req.CourseDiscussStudentLogQueryDTO;
import com.xinqi.modules.discuss.discuss.dto.req.CourseDiscussStudentLogUpdateDTO;
import com.xinqi.modules.discuss.discuss.dto.rsp.CourseDiscussStudentLogResultDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 降级处理
 *
 * @author: wenjie
 * @date: 2023/10/30
 */
@Slf4j
@Component
public class CourseDiscussStudentLogFallbackFactory implements FallbackFactory<CourseDiscussStudentLogClient> {

    @Override
    public CourseDiscussStudentLogClient create(Throwable throwable) {
        log.error("日志服务调用失败:{}", throwable.getMessage());
        return new CourseDiscussStudentLogClient() {
            @Override
            public R<PageInfo<CourseDiscussStudentLogResultDTO>> page(CourseDiscussStudentLogQueryDTO dto) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<CourseDiscussStudentLogResultDTO> findById(Long id) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Long> insert(CourseDiscussStudentLogCreateDTO dto) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Boolean> update(Long id, CourseDiscussStudentLogUpdateDTO dto) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Boolean> delete(Long id) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }
        };
    }
}